//
//  YZCardCell.m
//  VET
//
//  Created by Lam BG on 2018/7/16.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZCardCell.h"

#import "YZCardModel.h"

#import "UIView+Frame.h"
#import "CALayer+Additions.h"
//#import <QuartzCore/QuartzCore.h>

@interface YZCardCell ()

@property (weak, nonatomic) IBOutlet UIView *titleCoverView;
@property (weak, nonatomic) IBOutlet UIView *shadowView;


@property (nonatomic, weak) CAGradientLayer *gradientLayer;
@property (weak, nonatomic) IBOutlet UIImageView *reverseCorner;
@property (weak, nonatomic) IBOutlet UIView *spacingLine;


// 标题
@property (weak, nonatomic) IBOutlet UILabel *cardTitle;
// 图片
@property (weak, nonatomic) IBOutlet UIImageView *cardImgView;


// 消息 message
@property (weak, nonatomic) IBOutlet UILabel *messageInfoLabel;
@property (weak, nonatomic) IBOutlet UILabel *messageLabel;
@property (weak, nonatomic) IBOutlet UILabel *subMessageLabel;



// 更新展示
@property (weak, nonatomic) IBOutlet UILabel *updateTimeLabel;
@property (weak, nonatomic) IBOutlet UIView *tipsView;
@property (weak, nonatomic) IBOutlet UILabel *tips;

// 无更新
@property (weak, nonatomic) IBOutlet UILabel *emptyTips;

@end

@implementation YZCardCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code

    self.reverseCorner.layer.transform = CATransform3DMakeRotation(M_PI, 0, 1, 0);
    // line
    [self.spacingLine.layer drawLineOfDashByCAShapeLayer:self.spacingLine lineLength:6 lineSpacing:2.5 lineColor:kColorWithHexAlpha(0x979797, 0.25) lineDirection:YES];
    
    // shadow
    self.shadowView.layer.shadowOffset = CGSizeMake(0, 2);
    self.shadowView.layer.shadowOpacity = 0.5;
    self.shadowView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
    
    UIColor *color1 = kColorWithHexAlpha(0x000000, 0.5);
    UIColor *color2 = kColorWithHexAlpha(0x000000, 0.0);
    
    NSArray *colors = [NSArray arrayWithObjects:(id)color1.CGColor, color2.CGColor, nil];
    NSArray *locations = [NSArray arrayWithObjects:@(0.0), @(1.0), nil];
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = colors;
    gradientLayer.locations = locations;
    gradientLayer.frame = self.titleCoverView.bounds;
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint   = CGPointMake(0, 1);
    self.titleCoverView.layer.mask = gradientLayer;
    [self.titleCoverView.layer addSublayer:gradientLayer];
    self.gradientLayer = gradientLayer;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGRect frame = self.gradientLayer.frame;
    frame.size.width = self.bounds.size.width;
    frame.size.height += 10;
    self.gradientLayer.frame = frame;
}

- (void)setupCard:(YZCardModel*)model {
    
    self.cardTitle.text = model.cardTitle;
    self.cardImgView.image = [UIImage imageNamed:model.imageName];
    
    self.messageInfoLabel.text = model.messageInfo;
    
    NSString *message = model.message;
    self.messageLabel.text   = message;
    self.messageLabel.hidden = message.length == 0;
    
    NSString *subMessage = model.subMessage;
    self.subMessageLabel.text   = subMessage;
    self.subMessageLabel.hidden = subMessage.length == 0;
    
    
    // 更新展示
    self.tips.hidden = model.dateMsg.length == 0;
    self.tipsView.hidden = model.dateMsg.length == 0;
    self.updateTimeLabel.hidden = model.dateMsg.length == 0;
    self.tips.text = model.tips;
    self.updateTimeLabel.text = model.dateMsg;
    
    // 无更新
    self.emptyTips.hidden = model.dateMsg.length != 0;    
}

@end
















